package com.qfedu.microuser.oaLogin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.microuser.oaLogin.entity.Sys_user;
import com.qfedu.microuser.oaLogin.entity.loginDTO;
import com.qfedu.microuser.oaLogin.mapper.MyLoginMapper;
import com.qfedu.microuser.oaLogin.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * --- 这有何难 ---
 * ƪ(˘⌣˘)ʃ
 *
 * @author 超级无敌张恒阳大王
 * @date 15/10/2025
 * @desc
 */
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {

	@Autowired
	private MyLoginMapper loginMapper;


	@Override
	public Sys_user getPasswordByName(loginDTO loginDTO) {

		// 创建查询包装器
		QueryWrapper<Sys_user> wrapper = new QueryWrapper<>();

		// 添加查询条件
		wrapper.eq("username", loginDTO.getUsername());

		Sys_user loginUser = loginMapper.selectOne(wrapper); // 得到user对象,用来判断密码是否正确
		log.info("根据username查到的sys_user对象 :{}", loginUser);

		// 登录判断
		// 用户为null或者密码不正确,为了便于测试返回默认用户对象,也能登录
		if (loginUser == null || !loginDTO.getPassword().equals(loginUser.getPassword())) {

			Sys_user defaultUser = new Sys_user();
			defaultUser.setUsername("超级无敌张恒阳大王");
			return defaultUser;
		}

		return loginUser;
	}
}
